<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use DB;
use Flash;

class Amiba extends Model
{

    public function ajaxIndex()
    {
        $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $search_pattern = request('search.regex', true); /*是否启用模糊搜索*/
     
        $status = request('status' ,'');
        $bar = request('bar' ,'');
        $zixun = request('zixun' ,'');
        $yuyue = request('yuyue' ,'');
        $zhongzhi_yuyue = request('zhongzhi_yuyue' ,'');
        $zhengji_yuyue = request('zhengji_yuyue' ,'');
        $zhuanhua= request('zhuanhua' ,'');
        $daozhen = request('daozhen' ,'');
        $zhongzhi_daozhen = request('zhongzhi_daozhen' ,'');
        $zhengji_daozhen = request('zhengji_daozhen' ,'');
        $daozhen_zhuanhua = request('daozhen_zhuanhua' ,'');
        $yuji_shouru = request('yuji_shouru' ,'');
        $lirun = request('lirun' ,'');
    	$created_at_to = request('created_at_to' ,'');
        
        $created_at_from = request('created_at_from');
     
      
         /*权限创建时间搜索*/
		
            
                
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM i_table";
        $sqlCount .= " WHERE is_del = 0";
        if(trim($zixun)){
             $sqlCount .= "  AND zixun like '%" . $zixun . "%'";
        }
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        
        if($created_at_to){
			$sqlCount .= " AND time = '$created_at_to'";	
	}
                
        
       if($status){
			$sqlCount .= " AND status = $status";	
	}
         if($bar){
			$sqlCount .= " AND bar = $bar";	
	}
        
                
                
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM i_table";
        
        $sql .= " WHERE is_del = 0";
        /*状态搜索*/
        if (trim($zixun)) {
            $sql .= " AND  zixun like '%" . $zixun . "%'";
        }
        
          if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
        
         
            
        
        
        if($status){
			$sql .= " AND status = $status";	
	}
       if($bar){
			$sql .= " AND bar = $bar";	
	}
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
       
        
       
        
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    
    
    public  function  ajaxCount()
    {
        
        $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
           
         $zixun  = request('zixun','');
         $lirun  = request('lirun','');
         $yuji_shouru  = request('yuji_shouru','');
         $bar  = request('bar','');
             $created_at_from = request('created_at_from');
        
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM count_amb";
        $sqlCount .= " WHERE is_del = 0";
  
      if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
         if($bar){
			$sqlCount .= " AND bar = $bar";	
	}
        
                
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM count_amb";
        
        $sql .= " WHERE is_del = 0";
        
        
         if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
         if($bar){
			$sql .= " AND bar = $bar";	
	}
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
 
         
        
        
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);         
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    
    public function ajaxProject()
    {
        
        $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
      
        $daozhen = request('daozhen' ,'');
        $yuji_shouru = request('yuji_shouru' ,'');
        $lirun = request('lirun' ,'');
         $status = request('status' ,'');
         	$created_at_to = request('created_at_to' ,'');
                 
        $created_at_from = request('created_at_from');
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM count_project";
        $sqlCount .= " WHERE is_del = 0";
       if($created_at_to){
			$sqlCount .= " AND time = '$created_at_to'";	
	}
                
        
       if($status){
			$sqlCount .= " AND status = $status";	
	}
        
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM count_project";
        
        $sql .= " WHERE is_del = 0";
        /*状态搜索*/
    
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
       
            
       if($status){
			$sql .= " AND status = $status";	
	}
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
       
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    
    
 
    
    
 
    public function ajaxbar1()
    {
         
        $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $time = date('Y-m-d');
              
    
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 1 ";
        
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        
        
        
        
        
        
        
    
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 1 ";
        /*状态搜索*/
    
           if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";

        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
     
    public function ajaxbar2()
    {
        
          $time = date('Y-m-d');
        $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
           $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 2";
          if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 2  ";
        /*状态搜索*/
    
            if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
     
       
    public function ajaxbar3()
    {
        
          $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 3   ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 3  ";
        /*状态搜索*/
         if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    public function ajaxbar4()
    {
        
          $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 4    ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 4   ";
        /*状态搜索*/
    
             if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
     
    public function ajaxbar5()
    {
        
          $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 5  ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 5    ";
        /*状态搜索*/
    
             if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
     
    public function ajaxbar6()
    {
        
          $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
      
          
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 6  ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 6 ";
        /*状态搜索*/
    
        
             if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
     
    public function ajaxbar7()
    {
        
          $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 7 ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 7 ";
        /*状态搜索*/
    
             if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
     
    public function ajaxbar8()
    {
        
          $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 8  ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 8   ";
        /*状态搜索*/
    
             if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
     
    public function ajaxbar9()
    {
        
          $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and bar = 9   ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0  and bar = 9   ";
        /*状态搜索*/
         if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    
    
     public function ajaxproject1()
    {
         
           $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
        
        $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and status = 1  ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0 and status = 1   ";
        /*状态搜索*/
         /*状态搜索*/
         if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
    
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
       
    
    
    
     public function ajaxproject2()
    {
         
           $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
              $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and status = 2    ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        
        
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0 and status = 2  ";
        /*状态搜索*/
    
         /*状态搜索*/
         if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    
    
     public function ajaxproject3()
    {
         
           $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
              $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and status = 3 ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0 and status = 3    ";
        /*状态搜索*/
     /*状态搜索*/
         if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    
    
    
     public function ajaxproject4()
    {
         
           $time = date('Y-m-d');
          $draw = request('draw', 1);/*获取请求次数*/
        $start = request('start', config('admin.global.list.start')); /*获取开始*/
        $length = request('length', config('admin.global.list.length')); ///*获取条数*/
              $guanggao_id = request('guanggao_id','');
        $type_id = request('type_id','');
        $created_at_from = request('created_at_from','');
        
        $sqlCount = "SELECT COUNT(*) AS `sum` FROM price_table";
        $sqlCount .= " WHERE is_del = 0 and status = 4  ";
        if($type_id){
			$sqlCount .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sqlCount .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sqlCount .= " AND time = '$created_at_from'";	
	}
        $count = DB::select($sqlCount);
        $sql = "SELECT * FROM price_table";
        
        $sql .= " WHERE is_del = 0 and status = 4   ";
        /*状态搜索*/
         /*状态搜索*/
         if($type_id){
			$sql .= " AND type_id = $type_id";	
	}
        
         if($guanggao_id){
			$sql .= " AND guanggao_id = $guanggao_id";	
	}
        
        
        if($created_at_from){
			$sql .= " AND time = '$created_at_from'";	
	}
        
    
        
        
       $sql .= " ORDER BY id DESC
                LIMIT ?
                OFFSET ?";
       
        $list = DB::select($sql, array($length, $start));
        //return $list;
        $list = json_encode($list, true);
        $list = json_decode($list, true);
                
        if ($list) {
            foreach ($list as &$v) {
               
                 $v['wincomebutton'] = self::getTypeValueButton($v).self::getTypeKeyButton($v);     
            }
        }
        return [
            'draw' => $draw,
            'recordsTotal' => $count[0]->sum,
            'recordsFiltered' => $count[0]->sum,
            'data' => $list,
        ];
    }
    
    
    
    //编辑
    public function getTypeValueButton($v)
    {
      
        return '<a href="#" class="btn btn-xs btn-info tooltips" data-original-title="编辑"  data-placement="top">编辑</a>';

    }
    
    
    //查看
    public function getTypeKeyButton($v)
    {
        return '<a href="#" class="btn btn-xs btn-info tooltips" data-original-title="查看"  data-placement="top">查看</a>';
    }
    
    public function ajaxadd($data)
    {
       $info = DB::table('i_table')->insert($data);
       
	if($info){
           Flash::success(trans('alerts.amiba.created_success'));
            return true;
        }else{
            Flash::error(trans('alerts.amiba.created_error'));
            return false;
        }	

		
	
    }
  
    
 
        
        
 
}
